package com.jar.netty_demo.NIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 使用channel的transferFrom方法进行文件拷贝
 */
public class TransferFromDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("test.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("test3.txt");
        FileChannel channel = fileInputStream.getChannel();
        FileChannel channel1 = fileOutputStream.getChannel();
        channel1.transferFrom(channel, 0, channel.size());
        //关闭流
        channel.close();
        channel1.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
